package com.ruoyi.receipt.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.receipt.domain.TbRecordOnlineUser;
import com.ruoyi.receipt.service.ITbRecordOnlineUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 记录在线用户Controller
 * 
 * @author ruoyi
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/receipt/recordOnlineUser")
public class TbRecordOnlineUserController extends BaseController
{
    @Autowired
    private ITbRecordOnlineUserService tbRecordOnlineUserService;

    @Autowired
    private IdWorker idWorker;

    /**
     * 查询记录在线用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbRecordOnlineUser tbRecordOnlineUser)
    {
        startPage();
        List<TbRecordOnlineUser> list = tbRecordOnlineUserService.selectTbRecordOnlineUserList(tbRecordOnlineUser);
        return getDataTable(list);
    }

    /**
     * 导出记录在线用户列表
     */
    @Log(title = "导出在线用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbRecordOnlineUser tbRecordOnlineUser)
    {
        List<TbRecordOnlineUser> list = tbRecordOnlineUserService.selectTbRecordOnlineUserList(tbRecordOnlineUser);
        ExcelUtil<TbRecordOnlineUser> util = new ExcelUtil<TbRecordOnlineUser>(TbRecordOnlineUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取记录在线用户详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbRecordOnlineUserService.selectTbRecordOnlineUserById(id));
    }

    /**
     * 新增记录在线用户
     */
    @Log(title = "新增在线用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRecordOnlineUser tbRecordOnlineUser)
    {
        tbRecordOnlineUser.setId(idWorker.nextId());
        return toAjax(tbRecordOnlineUserService.insertTbRecordOnlineUser(tbRecordOnlineUser));
    }

    /**
     * 修改记录在线用户
     */
    @Log(title = "修改在线用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRecordOnlineUser tbRecordOnlineUser)
    {
        return toAjax(tbRecordOnlineUserService.updateTbRecordOnlineUser(tbRecordOnlineUser));
    }

    /**
     * 删除记录在线用户
     */
    @Log(title = "删除在线用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbRecordOnlineUserService.deleteTbRecordOnlineUserByIds(ids));
    }
}
